const customerIndividualTemplate = `
  <el-card class="box-card">
    <div slot="header" style="display: flex; justify-content: space-between;" class="clearfix">
      <span>动态信息</span>
      <el-button type="primary" :disabled="$attrs.islook" @click="isVisible = true">+预约信息</el-button>
    </div>
    <div>
    <el-timeline :reverse="reverse">
    <el-timeline-item
      v-for="(activity, index) in activities"
      :key="index"
      :color="activity.color"
      :timestamp="activity.insertTime" placement="top">
      <el-card>
        <h4>{{ activity.teacherName }} {{ activity.note }}</h4>
        <p>预约日期 {{ activity.preTime }} 跟进状态 {{ getStatusText(activity.status) }}</p>
      </el-card>
    </el-timeline-item>
  </el-timeline>
    </div>
    <el-dialog :visible.sync="isVisible" title="预约信息">
      <el-form :model="form" label-width="72px" size="small">
      <el-row>
        <el-col :span="12">
          <el-form-item label="跟进状态" prop="">
          <el-select v-model="form.status" placeholder="请选择">
        <el-option label="初步沟通" value="1"></el-option>
            <el-option label="持续跟进" value="2"></el-option>
            <el-option label="方案分析"  value="3"></el-option>
            <el-option label="制定方案"  value="4"></el-option>
            <el-option label="成交" value="5"></el-option>
            <el-option label="跟进失败" value="6"></el-option>
      </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="预约时间" prop="">
          <el-date-picker
          v-model="form.pre_time"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期">
        </el-date-picker></el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="任务描述" prop="">
          <el-input v-model="form.note"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleAddPre">确 定</el-button>
      </span>
    </el-dialog>
  </el-card>
`;

Vue.component('app-customer-individual', {
  name: 'app-customer-individual',
  template: customerIndividualTemplate,
  props: ['id'],
  created() {
    this.getList();
  },
  data() {
    return {
      isVisible: false,
      reverse: true,
      form: {
        status: '',
        pre_time: '',
        note: '',
      },
      activities: [],
    };
  },
  methods: {
    getStatusText(status) {
      switch (status) {
        case '1':
          return '初步沟通';
        case '2':
          return '持续跟进';
        case '3':
          return '方案分析';
        case '4':
          return '制定方案';
        case '5':
          return '成交';
        case '6':
          return '跟进失败';
        default:
          return '';
      }
    },
    getList() {
      $.ajax({
        url: `${baseUrl}preStudent/getRecorder?preStudentId=${this.id}`,
        method: 'Get',
        headers: {
          Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
        },
        success: (response) => {
          if (response.code === 200) {
            this.activities = response.data.map((item, index) => {
              index === response.data.length - 1 && (item.color = '#0099ff');
              return item;
            });
          }
        },
        error: (err, res, res1) => {
          this.$message({
            message: err.responseJSON.message || '网络错误',
            type: 'error',
          });
        },
      });
    },
    handleAddPre() {
      const data = {
        preStudentId: this.id,
        ...this.form,
      };
      $.ajax({
        url: baseUrl + 'preStudent/addRecorder',
        method: 'post',
        headers: {
          Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
        },
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify(data),
        // mimeType: 'multipart/form-data',
        success: (response) => {
          if (response.code === 200) {
            this.isVisible = false;
            this.getList();
          }
        },
      });
    },
  },
});
